#include <iostream>
#include <string>
#include <list>
#include <limits> 
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <cstring> 
#include <climits> 
#include <cmath>  
using namespace std;
typedef unsigned long long LONG;
typedef list<LONG> MEMORY;

class Number {
	private:
		MEMORY _memory;
	public:
		Number() { }
		~Number() {_memory.clear();}
		Number(const string& num) {
			LONG n;
			for(short p = 0; p < num.size();) {
				short pos = _DCOUNT;
				stringstream formater;
				while(num[p+pos] == '0') pos--;
				formater.str("");
				formater.clear();
				formater << num.substr(p, pos);
				formater >> n;
				_memory.push_back(n);
				p += pos;
			}
		}
		Number(const Number& ref){
			_memory = ref();
		}
		const MEMORY& operator()() const {return _memory;}
		operator string () const {
			stringstream formater;
			MEMORY::const_iterator it = _memory.begin();
			while(it != _memory.end()) {formater << *it; it++;}
			return formater.str();
		}
		const Number& operator = (const Number& ref) {
			_memory = ref();
			return *this;
		}
		const Number& operator = (const string& num) {
			LONG n;
			_memory.clear();
			for(short p = 0; p < num.size();) {
				short pos = _DCOUNT;
				stringstream formater;
				while(num[p+pos] == '0') pos--;
				formater.str("");
				formater.clear();
				formater << num.substr(p, pos);
				formater >> n;
				_memory.push_back(n);
				p += pos;
			}
			return *this;
		}
		bool operator == (const Number& v) const {
			return (_memory == v());
		}
		const Number& operator += (const Number& v); 
		Number operator + (const Number& v) const {
			Number r(*this);
			r += v;
			return r;
		} 
		friend ostream& operator << (ostream& out, const Number& v);
	private:
};

ostream& operator <<(ostream& out, const Number& v) {
	return out << (string)v;	
}

const Number& Number::operator += (const Number& v) {
	MEMORY::const_reverse_iterator us, vs, ue, ve;
	MEMORY u = _memory;
	_memory.clear();
	if(u.size() >= v().size()){
		us = u.rbegin(); ue = u.rend();
		vs = v().rbegin(); ve = v().rend();
	} else {
		vs = u.rbegin(); ve = u.rend();
		us = v().rbegin(); ue = v().rend();
	}
	LONG r = 0, c = 0;
	string num;
	stringstream formater;
	while(us != ue){
		if(vs != ve) {
			r = c + *us + *vs;
			if(r > _BUCKET) {
				num.clear();
				formater.clear();
				formater.str("");
				formater << r;
				num = formater.str();
				short pos = _DCOUNT;
				while (num[pos] == '0') pos--;
				if(pos == 0)
				formater << num.substr(0, pos);
				formater >> r;
				_memory.push_front(r);
				formater << num.substr(pos);
				formater >> c;
			} else {
				_memory.push_front(r);
				c = 0;
			}
			vs++;
		} else {
			r = c + *us;
			if(r > _BUCKET) {
				num.clear();
				formater.clear();
				formater.str("");
				formater << r;
				num = formater.str();
				short pos = _DCOUNT;
				while (num[pos] == '0') pos--;
				formater << num.substr(0, pos);
				formater >> r;
				_memory.push_front(r);
				formater << num.substr(pos);
				formater >> c;
			} else {
				_memory.push_front(r);
				c = 0;
			}
		}
		if(c != 0) _memory.push_front(c);
		us++;
	}
	return *this;		
}

int main() {
	Number u, v, x, r;
		u = "301524930363690898793191094388756585275425797807761063539419445522857976917366011116076368412951414810827477878712331275362021118936122887520610551766855113862195482429059111915641418217196725843586225033860874583848";
	v = "767929203586448095208634138841697124318383348538365254101375407530945306472028523817046243634423653930731168962924613894106638463521882143716452108327604261024386238380500009079029652423046956729989043256956244899193"; 
	x = "1955776131047003201738695204667239082599057050598018520402768262607601532812540012188594899203481994264501327182299481824342301904163404159870505930244056145161977398127193741161492303240405718081867148511647744784674";
	r = "4981006396044145397479215642564931874791923247542163358446331378269006349014474559310312410454339057270561301206235908818153263390784813350978074520582571665210536517063946603317655677121055118737309565314112609052389";
	cout << (x+x+v+u) << endl;
	cout << r << endl;
	cout << ((x+x+v+u)() == r()) << endl;
	//u = "9999999999999999999";
	//v = "9999999999999999999";
	//cout << (u+v) << endl;
	return 0;
}
